package cn.zhibang.sannuo.user_detection.service.impl;

import cn.zhibang.sannuo.commons.model.Customer;
import cn.zhibang.sannuo.user_detection.dao.UCustomerDao;
import cn.zhibang.sannuo.user_detection.service.UCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class UCustomerServiceImpl implements UCustomerService {

    @Autowired
    private UCustomerDao uCustomerDao;


    @Override
    public List<Customer> getCustomer(String name, String phone, String bname) {
        return uCustomerDao.getCustomer(name, phone, bname);
    }

    @Override
    public int addCustomer(Customer customer) {
        String getcount = getcount(customer.getIdentityCard());//根据身份证号查询这个人是否来过
        System.out.println(getcount);
        if(getcount == null){//等于0，表示这个人未来检查过，执行添加。否则执行修改
            return uCustomerDao.addCustomer(customer);
        }else {
            return uCustomerDao.updatecount(customer);
        }
    }

    @Override
    public String getcount(String identityCard){
        return uCustomerDao.getcount(identityCard);
    }

    @Override
    public int updatecount(Customer customer) {
        return uCustomerDao.updatecount(customer);
    }
}
